﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BLL
{
    /// <summary>
    /// BillingDetails
    /// </summary>
    public class BillingDetails
    {
        private readonly Aliyeye.Car.Net.Dal.BillingDetails dal = new Aliyeye.Car.Net.Dal.BillingDetails();
        public BillingDetails()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int BillingDetailsID)
        {
            return dal.Exists(BillingDetailsID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.BillingDetails model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.BillingDetails model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int BillingDetailsID)
        {

            return dal.Delete(BillingDetailsID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string BillingDetailsIDlist)
        {
            return dal.DeleteList(BillingDetailsIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.BillingDetails GetModel(int BillingDetailsID)
        {
            return dal.GetModel(BillingDetailsID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        //public Model.BillingDetails GetModelByCache(int BillingDetailsID)
        //{

        //    string CacheKey = "BillingDetailsModel-" + BillingDetailsID;
        //    object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = dal.GetModel(BillingDetailsID);
        //            if (objModel != null)
        //            {
        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch { }
        //    }
        //    return (BLL.Model.BillingDetails)objModel;
        //}

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.BillingDetails> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.BillingDetails> DataTableToList(DataTable dt)
        {
            List<Model.BillingDetails> modelList = new List<Model.BillingDetails>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.BillingDetails model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.BillingDetails();
                    if (dt.Rows[n]["BillingDetailsID"].ToString() != "")
                    {
                        model.BillingDetailsID = int.Parse(dt.Rows[n]["BillingDetailsID"].ToString());
                    }
                    model.IntoSectionID = int.Parse(dt.Rows[n]["IntoSectionID"].ToString());
                    model.CustomerID = int.Parse(dt.Rows[n]["CustomerID"].ToString());
                    if (dt.Rows[n]["IntoSectionDate"].ToString() != "")
                    {
                        model.IntoSectionDate = DateTime.Parse(dt.Rows[n]["IntoSectionDate"].ToString());
                    }
                    if (dt.Rows[n]["InpuTime"].ToString() != "")
                    {
                        model.InpuTime = DateTime.Parse(dt.Rows[n]["InpuTime"].ToString());
                    }
                    model.IntoSectionType = dt.Rows[n]["IntoSectionType"].ToString();
                    model.ImportBank = dt.Rows[n]["ImportBank"].ToString();
                    model.ImportBankAccount = dt.Rows[n]["ImportBankAccount"].ToString();
                    model.CollectionType = dt.Rows[n]["CollectionType"].ToString();
                    model.ReceivingBank = dt.Rows[n]["ReceivingBank"].ToString();
                    model.ReceivingBankAccount = dt.Rows[n]["ReceivingBankAccount"].ToString();
                    model.ReceivingBankCom = dt.Rows[n]["ReceivingBankCom"].ToString();
                    if (dt.Rows[n]["ImportAmount"].ToString() != "")
                    {
                        model.ImportAmount = decimal.Parse(dt.Rows[n]["ImportAmount"].ToString());
                    }
                    if (dt.Rows[n]["EndBookDate"].ToString() != "")
                    {
                        model.EndBookDate = DateTime.Parse(dt.Rows[n]["EndBookDate"].ToString());
                    }
                    if (dt.Rows[n]["InputUserID"].ToString() != "")
                    {
                        model.InputUserID = int.Parse(dt.Rows[n]["InputUserID"].ToString());
                    }
                    model.IntoSectionContent = dt.Rows[n]["IntoSectionContent"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}
